package javabase.xml.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * @Auther: luzhanshi
 * @Date: 2021/2/21 - 02 - 21 - 22:42 
 * @Description: javabase.xml.jsoup
 * @version: 1.0
 */
public class JsoupDemo2 {
    public static void main(String[] args) throws IOException {
        //2.2解析xml字符串，加载到内存，获取DOM树--->Document
//        Document document = Jsoup.parse("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
//                "\n" +
//                "<students>\n" +
//                "    <student number=\"s1001\">\n" +
//                "        <name>tom</name>\n" +
//                "        <age>18</age>\n" +
//                "        <sex>1</sex>\n" +
//                "    </student>\n" +
//                "    <student number=\"s1002\">\n" +
//                "        <name>lisi</name>\n" +
//                "        <age>18</age>\n" +
//                "        <sex>0</sex>\n" +
//                "    </student>\n" +
//                "</students>");
        URL url = new URL("https://www.baidu.com");
        Document document = Jsoup.parse(url, 10000);
        //3.获取元素对象
        Elements names = document.getElementsByTag("name");
        System.out.println(document);
//        System.out.println(names.size());//2
//        //3.1获取第一个name的Element对象
//        Element element = names.get(0);
//        //3.2获取数据
//        String name = element.text();
//        System.out.println(name);//tom
    }
}
